﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Aletfa.LightManager.Editor;

namespace Aletfa.LightManager
{
    /// <summary>
    /// Interaction logic for EditorWindow.xaml
    /// </summary>
    public partial class EditorWindow : Window
    {
        public EditorWindow()
        {
            InitializeComponent();
            this.editor.AllowSaveChanged += editor_AllowSaveChanged;
        }

        public Unit DataSource
        {
            get { return this.editor.DataSource; }
            set { this.editor.DataSource = value; }
        }

        public event GenericEventHandler<Unit> UnitSaved
        {
            add { this.editor.UnitSaved += value; }
            remove { this.editor.UnitSaved -= value; }
        }

        public event GenericEventHandler<ValidationArgs> NameCheckRequested
        {
            add { this.editor.NameCheckRequested += value; }
            remove { this.editor.NameCheckRequested -= value; }
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            this.editor.Save();
            this.DialogResult = true;
            this.Close();
        }

        void editor_AllowSaveChanged(bool arg)
        {
            this.btnSave.IsEnabled = arg;
        }
    }
}
